#include "party-protocol/channel.hpp"
#include "party-protocol/packet.hpp"
#include "party-protocol/receiver.hpp"
#include <cstdio>
#include <functional>
#include <sys/socket.h>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <iostream>

enum channel_ids{
    music=1,
    vocal=2,
    sync_signal=3,
};

int main(){
    int s=socket(AF_INET, SOCK_DGRAM , 0);
    int flag=1;
    std::function<bool (Packet*)> channel_receive_callback=[&](Packet *p){
        return true;
    };
    int resend=1;
    int length=512;
    unsigned int latency=10400*length/512/resend;
    Channel a=Channel(music,channel_unreliable,resend,s,channel_receive_callback);
    std::ifstream attention("Attention.pcm",std::ios::binary|std::ios::in);
    char content[length];
    memset(content, 0, length);
    std::printf("Start sending\n");
    while(!attention.eof()){
        attention.read(content, length);
        a.send(content, length,latency);
    }
    std::printf("Done sending\n");
    Receiver r=Receiver(s);
    r.addChannel(&a);
}
